<template>
  <div class="dashboard-editor-container">
    <div>
      <el-card>
        <el-form :model="ruleForm" style="margin-top:10px;" size="mini" label-position="top" ref="ruleForm">
          <el-row :gutter="10">
            <!-- <el-col :lg="4" :md="6">
              <el-form-item label="批次号" prop="BATCHNO">
              <el-input size="mini" v-model="ruleForm.BATCHNO" placeholder="请选择批次号"></el-input>
            </el-form-item>
            </el-col> -->
            <!-- <el-col :lg="4" :md="6">
              <el-form-item label="渠道名称" prop="CHANNELTYPE">
              <el-select v-model="ruleForm.CHANNELTYPE" size="mini" clearable placeholder="请选择渠道">
                <el-option v-for="item in channelOption" :key="item.FIELDKEY" :label="item.FIELDVALUE"
                  :value="item.FIELDKEY"></el-option>
              </el-select>
            </el-form-item>
            </el-col> -->
            <el-col :lg="4" :md="6">
              <el-form-item label="抽样方式" prop="CHANNELTYPE">
              <el-select v-model="ruleForm.CHANNELTYPE" size="mini" clearable placeholder="请选择渠道">
                <el-option v-for="item in channelOption" :key="item.FIELDKEY" :label="item.FIELDVALUE"
                  :value="item.FIELDKEY"></el-option>
              </el-select>
            </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item label="开始日期" prop="BATCHBEGINDATE">
                <el-date-picker size="mini" style="width:100%;" v-model="ruleForm.BATCHBEGINDATE" type="date"
                  value-format="yyyyMMdd" :clearable='false' placeholder="开始日期" :picker-options="pickerOptionsStart"
                  @change="changeStart">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="4" :md="6">
              <el-form-item label="结束日期" prop="BATCHENDDATE">
                <el-date-picker style="width:100%;" size="mini" v-model="ruleForm.BATCHENDDATE" type="date"
                  value-format="yyyyMMdd" placeholder="结束日期" :picker-options="pickerOptionsEnd" @change="changeEnd"
                  :clearable='false'>
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :lg="6" :md="9" class="searchBtnMarginTop" :offset="2">
              <el-button type="primary" icon="el-icon-search" :loading="loading" size="mini" @click="querySummary">查询
              </el-button>
              <el-button type='warning' size='mini' icon='el-icon-refresh' @click="clearForm('ruleForm')">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </div>
    <el-row style="margin-top:20px" >
      <el-col>
        <el-card>
          <el-table :data="tableData" border highlight-current-row  ref="tableData">
            <el-table-column prop='BATCHNO' label='批次号'align="center"  width="100"></el-table-column>
            <el-table-column prop='CHANNELTYPE' label='渠道类型' align="center"></el-table-column>
            <el-table-column prop='CHANNELNAME' label='渠道名'align="center"  width="100"></el-table-column>
            <el-table-column prop='BATCHDATE' label='采集日期' align="center"  width="100"></el-table-column>
            <el-table-column prop='MATCHNO' label='规则列名'align="center"  width="130"></el-table-column>
            <el-table-column prop='MATCH' label='抽样选项值'align="center"  width="100"></el-table-column>
            <el-table-column prop='WEIGHT' label='抽样选项名' align="center"></el-table-column>
            <el-table-column prop='MATCHNAME' label='权重' align="center"></el-table-column>
            <el-table-column prop='NUM' label='笔数' align="center"></el-table-column>
          </el-table>
          <div style="text-align:right;margin-top:20px;" v-show="this.tableData">
            <el-pagination :current-page="currentPage" background @size-change="handleSizeChange"
              :page-sizes="[10,25,50,100]" :page-size="pageSize" layout="total,sizes, prev, pager, next, jumper"
              :total="tableTotal" @current-change="changePage"></el-pagination>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  // 发送接口
  import request from "@/common/utils/requestQC";
  import dictionary from '@/message/wfm/baseData/dictionaryManage/dictionaryQuery'
  import requestWFM from "@/common/utils/requestWFM";
  import Query from '@/message/QCManage/sampleManage/autoSampleRulesResult/query';
  // import batch from '@/message/QCManage/sampleManage/collectBatch/collectBatch';
  
  //批量上传
  export default {
    name: '',
    data() {
      return {
        channelOption: [],
        pickerOptionsStart: {
          disabledDate: (time) => {
            return time.getTime() > Date.now()
          }
        },
        pickerOptionsEnd: {
          disabledDate: (time) => {
            return time.getTime() > Date.now()
          }
        },
        tableTotal: 0,
        pageSize:10,
        currentPage: 1, //表格当前页
        tableData: [],
        ruleForm: {
          BATCHNO: '',//批次号
          CHANNELTYPE: '', //渠道
          BATCHBEGINDATE: this.getDay(-6),
          BATCHENDDATE: this.getDay(0),
        },
        loading: false,
      }
    },
    computed: {},
    created() {
    },
    mounted() {
      this.querySummary()
      this.channelQuery()
      // this.batchQuery()
    },
    watch: {},
    methods: {
       // 查询业务渠道
      async channelQuery() {
        let resBody = new dictionary();
        resBody.data.FIELDCODE = 'CHANNELTYPE'
        resBody.data.CurrPage = 1
        resBody.data.PageRowNum = 100
        let response = await requestWFM(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.channelOption = response.BODY.FIEDATA;
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 自动抽样汇总查询
      async querySummary() {
        let resBody = new Query()
        resBody.data.CHANNELTYPE = this.ruleForm.CHANNELTYPE
        resBody.data.BATCHNO = this.ruleForm.BATCHNO
        resBody.data.BATCHBEGINDATE = this.ruleForm.BATCHBEGINDATE
        resBody.data.BATCHENDDATE = this.ruleForm.BATCHENDDATE
        resBody.data.OPERAFLAG = '1'
        resBody.data.CurrPage = this.currentPage
        resBody.data.PageRowNum = this.pageSize
        let response = await request(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.tableData = response.BODY.RSPSTRUCT
          this.tableTotal = response.BODY.TotalRowNum
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      changePage(val) {
        this.currentPage = val;
        this.querySummary()
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.querySummary()
      },
      // 获取当天前一天
      getDay(day) {
        var dd = new Date();
        dd.setDate(dd.getDate() + day);
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
        var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
        return y + "" + m + "" + d;
      },
      //  开始日期
      changeStart() {
        this.pickerOptionsEnd = Object.assign({}, this.pickerOptionsEnd, {
          disabledDate: (time) => {
            if (this.ruleForm.BATCHBEGINDATE) {
              return time.getTime() < Date.parse(this.ruleForm.BATCHBEGINDATE.slice(0, 4) + '-' + this.ruleForm
                .BATCHBEGINDATE.slice(4, 6) +
                '-' + this.ruleForm.BATCHBEGINDATE.slice(6, 8)) - 8.64e7 || time.getTime() > Date.now();
            } else {
              return time.getTime() > Date.now();
            }
          }
        })
      },
      // 结束日期
      changeEnd() {
        this.pickerOptionsStart = Object.assign({}, this.pickerOptionsStart, {
          disabledDate: (time) => {
            if (this.ruleForm.BATCHENDDATE) {
              return time.getTime() > Date.parse(this.ruleForm.BATCHENDDATE.slice(0, 4) + '-' + this.ruleForm
                .BATCHENDDATE
                .slice(4, 6) + '-' +
                this.ruleForm.BATCHENDDATE.slice(6, 8)) || time.getTime() > Date.now();
            } else {
              return time.getTime() > Date.now();
            }
          }
        })
      },
      // 重置查询条件
      clearForm(item) {
        // 重置表格
        this.$refs["" + item].resetFields();
      },
    }
  }

</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
